/*
	Copyright 2008 Jay Elliott

	This file is part of libemath.

	libemath is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	libemath is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with libemath.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __CSPHERE_H_
#define __CSPHERE_H_

#include <cmath>

#include "cPoint3d.h"
#include "cPlane.h"
#include "macros.h"
#include "cAlignedBox.h"

namespace emath
{

class cSphere
{
private:
	cPoint3d pos;//position
	float rad;//radius

public:
	inline cSphere();
	inline cSphere(const cSphere& original);//copy constructor
	inline cSphere(const cPoint3d& loc, float radius);

	bool InFrustum(const cPlane frust[6]) const;
	inline bool intersects(const cSphere& other) const;
	bool intersects(cAlignedBox box);
	inline void translate(const cPoint3d& disp);
};

cSphere::cSphere()
{
}

cSphere::cSphere(const cSphere& original)
{
	pos = original.pos;
	rad = original.rad;
}

cSphere::cSphere(const emath::cPoint3d& loc, float radius)
{
	pos = loc;
	rad = fabs(radius);
}

bool cSphere::intersects(const cSphere& other) const
{
	if ((pos - other.pos).GetMag() > rad + other.rad + EPSILON)
		return false;
	return true;
}

void cSphere::translate(const emath::cPoint3d& disp)
{
	pos = pos + disp;
}

}
#endif
